package com.atguigui.leetcode;

/**
 * 824.山羊拉丁文
 * <p>
 * Project: leetcode
 * Package: com.atguigui.leetcode
 * Version: 1.0
 * <p>
 * Created by WJX on 2022/4/21 9:00
 */
public class P824GoatLatin {
    public static void main(String[] args) {
        Solution solution = new P824GoatLatin().new Solution();
        // TO TEST
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public String toGoatLatin(String sentence) {

            String word = "aeiouAEIOU";
            int index = 1;

            StringBuilder ans = new StringBuilder();

            for (String str : sentence.split(" ")) {

                char startStr = str.charAt(0);
                //判断是否是 aeiou 中的一个
                if (word.contains(startStr + "")) {
                    //在单词后添加"ma"，并加索引
                    ans.append(str + "ma");
                } else {
                    //移除第一个字符并将它放到末尾，之后再添加"ma"
                    String newStr = str.substring(1) + str.substring(0, 1);
                    ans.append(newStr + "ma");
                }
                for (int i = 0; i < index; i++) {
                    ans.append("a");
                }
                ans.append(" ");
                index++;
            }
            ans.delete(ans.length() - 1, ans.length());


            return ans.toString();
        }
    }
}
